package com.lwj.designpattern.creativemode.singletonmode;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {
    public static void main(String[] args) {
        // 懒汉的测试
        // 此时 有引用 singletonMode 指向了 SingletonMode的实例
        SingletonMode singletonMode = SingletonMode.getSingletonMode();
//        此时， 有引用指向了singletonMode1 SingletonMode的实例
        SingletonMode singletonMode1 = SingletonMode.getSingletonMode();

        System.out.println(singletonMode == singletonMode1 ? singletonMode :"不同实例");

        System.out.println("懒汉的测试");
        HungryMode instance = HungryMode.getInstance();
        HungryMode instance1 = HungryMode.getInstance();
        System.out.println(instance == instance1 ? instance1 :"不同实例");


        ExecutorService threadpool = Executors.newFixedThreadPool(20);

        for(int i = 0 ; i <20 ; i++) {
            threadpool.execute(new Runnable() {
                public void run() {
                    System.out.println(Thread.currentThread().getName() + ":" + HungryMode.getInstance());
                }
            });
        }


    }

}
